#ifndef __EXTI_H
#define __EXTI_H

#ifdef __cplusplus
 extern "C" {
#endif

/* Includes ------------------------------------------------------------------*/
#include "system_remap.h"

typedef enum
{
  EXTI_Mode_Interrupt = 0x00,
  EXTI_Mode_Event = 0x04
}EXTIMode_TypeDef;

/** 
  * @brief  EXTI Trigger enumeration  
  */

typedef enum
{
  EXTI_Trigger_Rising = 0x08,
  EXTI_Trigger_Falling = 0x0C,  
  EXTI_Trigger_Rising_Falling = 0x10
}EXTITrigger_TypeDef;

#define IS_EXTI_TRIGGER(TRIGGER) (((TRIGGER) == EXTI_Trigger_Rising) || \
                                  ((TRIGGER) == EXTI_Trigger_Falling) || \
                                  ((TRIGGER) == EXTI_Trigger_Rising_Falling))
/** 
  * @brief  EXTI Init Structure definition  
  */

typedef struct
{
  uint32_t EXTI_Line;               /*!< Specifies the EXTI lines to be enabled or disabled.
                                         This parameter can be any combination of @ref EXTI_Lines */
   
  EXTIMode_TypeDef EXTI_Mode;       /*!< Specifies the mode for the EXTI lines.
                                         This parameter can be a value of @ref EXTIMode_TypeDef */

  EXTITrigger_TypeDef EXTI_Trigger; /*!< Specifies the trigger signal active edge for the EXTI lines.
                                         This parameter can be a value of @ref EXTIMode_TypeDef */

  FunctionalState EXTI_LineCmd;     /*!< Specifies the new state of the selected EXTI lines.
                                         This parameter can be set either to ENABLE or DISABLE */ 
}EXTI_InitTypeDef;

/**
  * @}
  */

/** @defgroup EXTI_Exported_Constants
  * @{
  */

/** @defgroup EXTI_Lines 
  * @{
  */

#define EXTI_Line0       ((uint32_t)0x00001)  /*!< External interrupt line 0 */
#define EXTI_Line1       ((uint32_t)0x00002)  /*!< External interrupt line 1 */
#define EXTI_Line2       ((uint32_t)0x00004)  /*!< External interrupt line 2 */
#define EXTI_Line3       ((uint32_t)0x00008)  /*!< External interrupt line 3 */
#define EXTI_Line4       ((uint32_t)0x00010)  /*!< External interrupt line 4 */
#define EXTI_Line5       ((uint32_t)0x00020)  /*!< External interrupt line 5 */
#define EXTI_Line6       ((uint32_t)0x00040)  /*!< External interrupt line 6 */
#define EXTI_Line7       ((uint32_t)0x00080)  /*!< External interrupt line 7 */
#define EXTI_Line8       ((uint32_t)0x00100)  /*!< External interrupt line 8 */
#define EXTI_Line9       ((uint32_t)0x00200)  /*!< External interrupt line 9 */
#define EXTI_Line10      ((uint32_t)0x00400)  /*!< External interrupt line 10 */
#define EXTI_Line11      ((uint32_t)0x00800)  /*!< External interrupt line 11 */
#define EXTI_Line12      ((uint32_t)0x01000)  /*!< External interrupt line 12 */
#define EXTI_Line13      ((uint32_t)0x02000)  /*!< External interrupt line 13 */
#define EXTI_Line14      ((uint32_t)0x04000)  /*!< External interrupt line 14 */
#define EXTI_Line15      ((uint32_t)0x08000)  /*!< External interrupt line 15 */                                        
#define EXTI_Line16      ((uint32_t)0x10000)  /*!< External interrupt line 16 */
#define EXTI_Line17      ((uint32_t)0x00002)  /*!< External interrupt line 17 */
#define EXTI_Line18      ((uint32_t)0x00004)  /*!< External interrupt line 18 */
#define EXTI_Line19      ((uint32_t)0x00008)  /*!< External interrupt line 19 */
#define EXTI_Line20      ((uint32_t)0x00010)  /*!< External interrupt line 20 */
#define EXTI_Line21      ((uint32_t)0x00020)  /*!< External interrupt line 21 */
#define EXTI_Line22      ((uint32_t)0x00040)  /*!< External interrupt line 22 */
#define EXTI_Line23      ((uint32_t)0x00080)  /*!< External interrupt line 23 */
#define EXTI_Line24      ((uint32_t)0x00100)  /*!< External interrupt line 24 */
#define EXTI_Line25      ((uint32_t)0x00200)  /*!< External interrupt line 25 */                                        
#define EXTI_Line26      ((uint32_t)0x00400)  /*!< External interrupt line 26 */
#define EXTI_Line27      ((uint32_t)0x00800)  /*!< External interrupt line 27 */
#define EXTI_Line28      ((uint32_t)0x01000)  /*!< External interrupt line 28 */
#define EXTI_Line29      ((uint32_t)0x02000)  /*!< External interrupt line 29 */
#define EXTI_Line30      ((uint32_t)0x04000)  /*!< External interrupt line 30 */
#define EXTI_Line31      ((uint32_t)0x08000)  /*!< External interrupt line 31 */


//RTC
#define EXTI_LineRTC      ((uint32_t)0x20000)  /*!< External interrupt line 17 */

#define EXTI_A_Pin_0                 ((uint32_t)0x00000000)  /*!< Pin 0 selected */
#define EXTI_A_Pin_1                 ((uint32_t)0x00000000)  /*!< Pin 1 selected */
#define EXTI_A_Pin_2                 ((uint32_t)0x00000000)  /*!< Pin 2 selected */
#define EXTI_A_Pin_3                 ((uint32_t)0x00000000)  /*!< Pin 3 selected */
#define EXTI_A_Pin_4                 ((uint32_t)0x00000000)  /*!< Pin 4 selected */
#define EXTI_A_Pin_5                 ((uint32_t)0x00000000)  /*!< Pin 5 selected */
#define EXTI_A_Pin_6                 ((uint32_t)0x00000000)  /*!< Pin 6 selected */
#define EXTI_A_Pin_7                 ((uint32_t)0x00000000)  /*!< Pin 7 selected */
#define EXTI_A_Pin_8                 ((uint32_t)0x00000000)  /*!< Pin 8 selected */
#define EXTI_A_Pin_9                 ((uint32_t)0x00000000)  /*!< Pin 9 selected */
#define EXTI_A_Pin_10                ((uint32_t)0x00000000)  /*!< Pin 10 selected */
#define EXTI_A_Pin_11                ((uint32_t)0x00000000)  /*!< Pin 11 selected */
#define EXTI_A_Pin_12                ((uint32_t)0x00000000)  /*!< Pin 12 selected */
#define EXTI_A_Pin_13                ((uint32_t)0x00000000)  /*!< Pin 13 selected */
#define EXTI_A_Pin_14                ((uint32_t)0x00000000)  /*!< Pin 14 selected */
#define EXTI_A_Pin_15                ((uint32_t)0x00000000)  /*!< Pin 15 selected */
#define EXTI_A_Pin_16                ((uint32_t)0x00000001)  /*!< Pin 10 selected */
#define EXTI_A_Pin_17                ((uint32_t)0x00000004)  /*!< Pin 11 selected */
#define EXTI_A_Pin_18                ((uint32_t)0x00000010)  /*!< Pin 12 selected */
#define EXTI_A_Pin_19                ((uint32_t)0x00000040)  /*!< Pin 13 selected */
#define EXTI_A_Pin_20                ((uint32_t)0x00000100)  /*!< Pin 10 selected */
#define EXTI_A_Pin_21                ((uint32_t)0x00000400)  /*!< Pin 11 selected */
#define EXTI_A_Pin_22                ((uint32_t)0x00001000)  /*!< Pin 12 selected */
#define EXTI_A_Pin_23                ((uint32_t)0x00004000)  /*!< Pin 13 selected */
#define EXTI_A_Pin_24                ((uint32_t)0x00010000)  /*!< Pin 14 selected */
#define EXTI_A_Pin_25                ((uint32_t)0x00040000)  /*!< Pin 15 selected */
#define EXTI_A_Pin_26                ((uint32_t)0x00100000)  /*!< Pin 10 selected */
#define EXTI_A_Pin_27                ((uint32_t)0x00400000)  /*!< Pin 11 selected */
#define EXTI_A_Pin_28                ((uint32_t)0x01000000)  /*!< Pin 12 selected */
#define EXTI_A_Pin_29                ((uint32_t)0x04000000)  /*!< Pin 13 selected */
#define EXTI_A_Pin_30                ((uint32_t)0x10000000)  /*!< Pin 12 selected */
#define EXTI_A_Pin_31                ((uint32_t)0x40000000)  /*!< Pin 13 selected */
#define EXTI_B_Pin_0                 ((uint32_t)0x00000002)  /*!< Pin 0 selected */
#define EXTI_B_Pin_1                 ((uint32_t)0x00000008)  /*!< Pin 1 selected */
#define EXTI_B_Pin_2                 ((uint32_t)0x00000020)  /*!< Pin 2 selected */
#define EXTI_B_Pin_3                 ((uint32_t)0x00000080)  /*!< Pin 3 selected */
#define EXTI_B_Pin_4                 ((uint32_t)0x00000200)  /*!< Pin 4 selected */
#define EXTI_B_Pin_5                 ((uint32_t)0x00000800)  /*!< Pin 5 selected */
#define EXTI_B_Pin_6                 ((uint32_t)0x00002000)  /*!< Pin 6 selected */
#define EXTI_B_Pin_7                 ((uint32_t)0x00008000)  /*!< Pin 7 selected */
#define EXTI_B_Pin_8                 ((uint32_t)0x00020000)  /*!< Pin 8 selected */
#define EXTI_B_Pin_9                 ((uint32_t)0x00080000)  /*!< Pin 9 selected */
#define EXTI_B_Pin_10                ((uint32_t)0x00200000)  /*!< Pin 10 selected */
#define EXTI_B_Pin_11                ((uint32_t)0x00800000)  /*!< Pin 11 selected */
#define EXTI_B_Pin_12                ((uint32_t)0x02000000)  /*!< Pin 12 selected */



#define EXTI_PortSourceGPIOA       ((uint8_t)0x00)
#define EXTI_PortSourceGPIOB       ((uint8_t)0x01)

/** @defgroup EXTI_Pin_sources 
  * @{
  */ 
#define EXTI_PinSource0            ((uint8_t)0x00)
#define EXTI_PinSource1            ((uint8_t)0x01)
#define EXTI_PinSource2            ((uint8_t)0x02)
#define EXTI_PinSource3            ((uint8_t)0x03)
#define EXTI_PinSource4            ((uint8_t)0x04)
#define EXTI_PinSource5            ((uint8_t)0x05)
#define EXTI_PinSource6            ((uint8_t)0x06)
#define EXTI_PinSource7            ((uint8_t)0x07)
#define EXTI_PinSource8            ((uint8_t)0x08)
#define EXTI_PinSource9            ((uint8_t)0x09)
#define EXTI_PinSource10           ((uint8_t)0x0A)
#define EXTI_PinSource11           ((uint8_t)0x0B)
#define EXTI_PinSource12           ((uint8_t)0x0C)
#define EXTI_PinSource13           ((uint8_t)0x0D)
#define EXTI_PinSource14           ((uint8_t)0x0E)
#define EXTI_PinSource15           ((uint8_t)0x0F)
#define EXTI_PinSource16           ((uint8_t)0x10)
#define EXTI_PinSource17           ((uint8_t)0x11)
#define EXTI_PinSource18           ((uint8_t)0x12)
#define EXTI_PinSource19           ((uint8_t)0x13)
#define EXTI_PinSource20           ((uint8_t)0x14)
#define EXTI_PinSource21           ((uint8_t)0x15)
#define EXTI_PinSource22           ((uint8_t)0x16)
#define EXTI_PinSource23           ((uint8_t)0x17)
#define EXTI_PinSource24           ((uint8_t)0x18)
#define EXTI_PinSource25           ((uint8_t)0x19)
#define EXTI_PinSource26           ((uint8_t)0x1A)
#define EXTI_PinSource27           ((uint8_t)0x1B)
#define EXTI_PinSource28           ((uint8_t)0x1C)
#define EXTI_PinSource29           ((uint8_t)0x1D)
#define EXTI_PinSource30           ((uint8_t)0x1E)
#define EXTI_PinSource31           ((uint8_t)0x1F)

//RTC
#define EXTI_SourceRTC      ((uint32_t)0x20000)  /*!< External interrupt line 17 */

/**
  * @}
  */

/**
  * @}
  */

/** @defgroup EXTI_Exported_Macros
  * @{
  */

/**
  * @}
  */

/** @defgroup EXTI_Exported_Functions
  * @{
  */

void EXTI_DeInit(void);
void EXTI_Init(EXTI_InitTypeDef* EXTI_InitStruct);
void EXTI_StructInit(EXTI_InitTypeDef* EXTI_InitStruct);
void EXTI_GenerateSWInterrupt(uint32_t EXTI_Line);
FlagStatus EXTI_GetFlagStatus(uint32_t EXTI_Line);
void EXTI_ClearFlag(uint32_t EXTI_Line);
ITStatus EXTI_GetITStatus(uint32_t EXTI_Line);
void EXTI_ClearITPendingBit(uint32_t EXTI_Line);
void EXTI_LineConfig(uint8_t EXTI_PortSourceGPIOx, uint32_t EXTI_PinSourcex);

#ifdef __cplusplus
}
#endif

#endif /* __EXTI_H */
